import { Inject, Injectable } from '@nestjs/common';
import { NacosConfigClient } from 'nacos';

@Injectable()
export class NacosConfigClientService {
  private nacosConfigClient: NacosConfigClient;
  constructor(
    @Inject('NacosConfigClient') nacosConfigClient: NacosConfigClient,
  ) {
    this.nacosConfigClient = nacosConfigClient;
  }
  async getConfig(dataId: string, group: string, options?: any) {
    try {
      const data = await this.nacosConfigClient.getConfig(
        dataId,
        group,
        options,
      );
      return JSON.parse(data);
    } catch (e) {
      return null;
    }
  }
}
